package com.ruoyi.web.controller.statistics;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.UnitUtils;
import com.ruoyi.statistics.domain.StatisticsTrain;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.statistics.domain.StatisticsSupport;
import com.ruoyi.statistics.service.IStatisticsSupportService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.web.multipart.MultipartFile;

/**
 * 技术支持 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-11-11
 */
@Controller
@RequestMapping("/statistics/statisticsSupport")
public class StatisticsSupportController extends BaseController
{
    private String prefix = "statistics/statisticsSupport";
	
	@Autowired
	private IStatisticsSupportService statisticsSupportService;
	
	@RequiresPermissions("statistics:statisticsSupport:view")
	@GetMapping()
	public String statisticsSupport(ModelMap mmap)
	{
		List<StatisticsSupport> list = statisticsSupportService.selectStatisticsSupportList(new StatisticsSupport());
		mmap.put("supportcount", list.size());

		int daycount=0;
		int daycount1=0;
		int daycount2=0;
		int peoplecount=0;


		int daqing_count = 0;int daqing_xueyuan = 0;int daqing_teacher = 0;int liaohe_count = 0;int liaohe_xueyuan = 0;int liaohe_teacher = 0;
		int changqing_count = 0;int changqing_xueyuan = 0;int changqing_teacher = 0;int talimu_count = 0;int talimu_xueyuan = 0;int talimu_teacher = 0;
		int xinjiang_count = 0;int xinjiang_xueyuan = 0;int xinjiang_teacher = 0;int xinan_count = 0;int xinan_xueyuan = 0;int xinan_teacher = 0;
		int jilin_count = 0;int jilin_xueyuan = 0;int jilin_teacher = 0;int dagang_count = 0;int dagang_xueyuan = 0;int dagang_teacher = 0;
		int qinghai_count = 0;int qinghai_xueyuan = 0;int qinghai_teacher = 0;int huabei_count = 0;int huabei_xueyuan = 0;int huabei_teacher = 0;
		int tuha_count = 0;int tuha_xueyuan = 0;int tuha_teacher = 0;int jidong_count = 0;int jidong_xueyuan = 0;int jidong_teacher = 0;
		int yumen_count = 0;int yumen_xueyuan = 0;int yumen_teacher = 0;int meicengqi_count = 0;int meicengqi_xueyuan = 0;int meicengqi_teacher = 0;
		int nanfang_count = 0;int nanfang_xueyuan = 0;int nanfang_teacher = 0;int kantanbeijing_count = 0;int kantanbeijing_xueyuan = 0;int kantanbeijing_teacher = 0;
		int zhejiang_count = 0;int zhejiang_xueyuan = 0;int zhejiang_teacher = 0;int kantanxibei_count = 0;int kantanxibei_xueyuan = 0;int kantanxibei_teacher = 0;
		int hanzhoudizhi_count = 0;int hanzhoudizhi_xueyuan = 0;int hanzhoudizhi_teacher = 0;
		int dongfang_count = 0;int dongfang_xueyuan = 0;int dongfang_teacher = 0;

		for (int i = 0; i < list.size(); i++) {
			StatisticsSupport statisticsSupport = list.get(i);

			String explainday =statisticsSupport.getExplainday();
			if (StringUtils.isNotEmpty(explainday)){
				daycount+=Integer.parseInt(explainday);
				if (statisticsSupport.getType().contains("处理")){
					daycount1+=Integer.parseInt(explainday);
				}else if(statisticsSupport.getType().contains("解释")){
					daycount2+=Integer.parseInt(explainday);
				}
			}else{
				statisticsSupport.setExplainday("0");
			}
			String operatepeople =statisticsSupport.getOperatepeople();
			if (StringUtils.isNotEmpty(operatepeople)){
				peoplecount+=Integer.parseInt(operatepeople);
			}

			if (statisticsSupport.getUnitid().equals("1"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					daqing_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					daqing_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("2"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					liaohe_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					liaohe_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("3"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					changqing_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					changqing_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("4"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					talimu_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					talimu_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("5"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					xinjiang_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					xinjiang_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("6"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					xinan_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					xinan_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("7"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					jilin_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					jilin_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("8"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					dagang_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					dagang_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("9"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					qinghai_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					qinghai_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("10"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					huabei_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					huabei_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("11"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					tuha_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					tuha_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("12"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					jidong_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("处理")) {
					jidong_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("13"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					yumen_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					yumen_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("14"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					zhejiang_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					zhejiang_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("15"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					meicengqi_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					meicengqi_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("16"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					nanfang_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					nanfang_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("17"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					kantanbeijing_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					kantanbeijing_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("18"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					kantanxibei_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					kantanxibei_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("19")) {
				if (statisticsSupport.getType().contains("处理")) {
					hanzhoudizhi_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					hanzhoudizhi_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}
			else if (statisticsSupport.getUnitid().equals("20"))
			{
				if (statisticsSupport.getType().contains("处理")) {
					dongfang_xueyuan += Integer.parseInt(statisticsSupport.getExplainday());
				} else if (statisticsSupport.getType().contains("解释")) {
					dongfang_teacher += Integer.parseInt(statisticsSupport.getExplainday());
				}
			}

		}
		mmap.put("supportday", daycount);
		mmap.put("supportoperateday", daycount1);
		mmap.put("supportexplainday",daycount2);
		mmap.put("supportpeople", peoplecount);

		mmap.put("allcounts", daqing_xueyuan + daqing_teacher + "," + (liaohe_xueyuan + liaohe_teacher) + "," + (changqing_xueyuan + changqing_teacher) + "," + (talimu_xueyuan + talimu_teacher) + "," + (xinjiang_xueyuan + xinjiang_teacher) + "," + (xinan_xueyuan + xinan_teacher) + "," + (
				jilin_xueyuan + jilin_teacher) + "," + (dagang_xueyuan + dagang_teacher) + "," + (qinghai_xueyuan + qinghai_teacher) + "," + (huabei_xueyuan + huabei_teacher) + "," + (tuha_xueyuan + tuha_teacher) + "," + (jidong_xueyuan + jidong_teacher) + "," + (yumen_xueyuan + yumen_teacher) + "," + (
				zhejiang_xueyuan + zhejiang_teacher) + "," + (meicengqi_xueyuan + meicengqi_teacher) + "," + (nanfang_xueyuan + nanfang_teacher) + "," + (kantanbeijing_xueyuan + kantanbeijing_teacher) + "," + (kantanxibei_xueyuan + kantanxibei_teacher) + "," + (hanzhoudizhi_xueyuan + hanzhoudizhi_teacher) + "," + (dongfang_xueyuan + dongfang_teacher));
		mmap.put("operatecounts", daqing_xueyuan + "," + liaohe_xueyuan + "," + changqing_xueyuan + "," + talimu_xueyuan + "," + xinjiang_xueyuan + "," + xinan_xueyuan + "," +
				jilin_xueyuan + "," + dagang_xueyuan + "," + qinghai_xueyuan + "," + huabei_xueyuan + "," + tuha_xueyuan + "," + jidong_xueyuan + "," + yumen_xueyuan + "," +
				zhejiang_xueyuan + "," + meicengqi_xueyuan + "," + nanfang_xueyuan + "," + kantanbeijing_xueyuan + "," + kantanxibei_xueyuan + "," + hanzhoudizhi_xueyuan+ "," + dongfang_xueyuan);
		mmap.put("explaincounts", daqing_teacher + "," + liaohe_teacher + "," + changqing_teacher + "," + talimu_teacher + "," + xinjiang_teacher + "," + xinan_teacher + "," +
				jilin_teacher + "," + dagang_teacher + "," + qinghai_teacher + "," + huabei_teacher + "," + tuha_teacher + "," + jidong_teacher + "," + yumen_teacher + "," +
				zhejiang_teacher + "," + meicengqi_teacher + "," + nanfang_teacher + "," + kantanbeijing_teacher + "," + kantanxibei_teacher + "," + hanzhoudizhi_teacher+ "," + dongfang_teacher);

		return prefix + "/statisticsSupport";
	}
	
	/**
	 * 查询技术支持列表
	 */
	@RequiresPermissions("statistics:statisticsSupport:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(StatisticsSupport statisticsSupport)
	{
		startPage();
        List<StatisticsSupport> list = statisticsSupportService.selectStatisticsSupportList(statisticsSupport);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出技术支持列表
	 */
	@RequiresPermissions("statistics:statisticsSupport:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StatisticsSupport statisticsSupport)
    {
    	List<StatisticsSupport> list = statisticsSupportService.selectStatisticsSupportList(statisticsSupport);
        ExcelUtil<StatisticsSupport> util = new ExcelUtil<StatisticsSupport>(StatisticsSupport.class);
        return util.exportExcel(list, "statisticsSupport");
    }


	@PostMapping("/importData")
	@ResponseBody
	public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
	{
		ExcelUtil<StatisticsSupport> util = new ExcelUtil<StatisticsSupport>(StatisticsSupport.class);
		List<StatisticsSupport> supportList = util.importExcel(file.getInputStream());
		for (StatisticsSupport statisticsSupport:supportList) {
			statisticsSupport.setUnitid(UnitUtils.getUnitId(statisticsSupport.getUnit()));
			statisticsSupportService.insertStatisticsSupport(statisticsSupport);
		}
		return AjaxResult.success("导入成功");
	}

	/**
	 * 新增技术支持
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存技术支持
	 */
	@RequiresPermissions("statistics:statisticsSupport:add")
	@Log(title = "技术支持", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(StatisticsSupport statisticsSupport)
	{
		statisticsSupport.setUnit(UnitUtils.unitById(statisticsSupport.getUnitid()));
		return toAjax(statisticsSupportService.insertStatisticsSupport(statisticsSupport));
	}

	/**
	 * 修改技术支持
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		StatisticsSupport statisticsSupport = statisticsSupportService.selectStatisticsSupportById(id);
		mmap.put("statisticsSupport", statisticsSupport);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存技术支持
	 */
	@RequiresPermissions("statistics:statisticsSupport:edit")
	@Log(title = "技术支持", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(StatisticsSupport statisticsSupport)
	{
		statisticsSupport.setUnit(UnitUtils.unitById(statisticsSupport.getUnitid()));
		return toAjax(statisticsSupportService.updateStatisticsSupport(statisticsSupport));
	}
	
	/**
	 * 删除技术支持
	 */
	@RequiresPermissions("statistics:statisticsSupport:remove")
	@Log(title = "技术支持", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(statisticsSupportService.deleteStatisticsSupportByIds(ids));
	}
	
}
